//
//  CustomView.swift
//  DesignDemo
//
//  Created by luoqiang on 16/3/25.
//  Copyright © 2016年 luoqiang. All rights reserved.
//

import UIKit

@IBDesignable
class CustomView: UIView {
    
    var view: UIView!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        view = loadViewFormNib()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        view = loadViewFormNib()
    }
    
    
    func loadViewFormNib() -> UIView {
        let boudle = NSBundle(forClass: CustomView.self)
        let nib = UINib(nibName: "CustomView", bundle: boudle)
        let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
        
        view.frame = bounds
        view.autoresizingMask = [.FlexibleWidth,.FlexibleHeight]
        addSubview(view)
        return view
    }
    
    @IBInspectable var borderWidth: CGFloat = 0 {
        didSet {
            layer.borderWidth = borderWidth
        }
    }
    @IBInspectable var borderColor: UIColor? {
        didSet {
            layer.borderColor = borderColor?.CGColor
        }
    }
}
